package com.matrix.review.converter;

import com.matrix.api.review.dto.ReviewDTO;
import com.matrix.api.review.dto.ReviewItemDTO;
import com.matrix.api.review.dto.ReviewReplyDTO;
import com.matrix.api.review.vo.ReviewItemVO;
import com.matrix.api.review.vo.ReviewReplyVO;
import com.matrix.api.review.vo.ReviewVO;
import com.matrix.review.entity.Review;
import com.matrix.review.entity.ReviewItem;
import com.matrix.review.entity.ReviewReply;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;


/**
 * @author 有点甜
 * @since 2025/8/5
 */
@Mapper
public interface ReviewConverter {

    ReviewConverter INSTANCE = Mappers.getMapper(ReviewConverter.class);

    @Mapping(target = "id", ignore = true)
    @Mapping(target = "userId", ignore = true)
    @Mapping(target = "shopId", ignore = true)
    @Mapping(target = "hasContent", ignore = true)
    @Mapping(target = "status", ignore = true)
    @Mapping(target = "comment", ignore = true)
    @Mapping(source = "anonymous", target = "isAnonymous")
    @Mapping(target = "createTime", ignore = true)
    @Mapping(target = "updateTime", ignore = true)
    Review toReview(ReviewDTO dto);

    @Mapping(target = "id", ignore = true)
    @Mapping(target = "reviewId", ignore = true)
    @Mapping(target = "productId", ignore = true)
    ReviewItem toReviewItem(ReviewItemDTO dto);

    @Mapping(target = "id", ignore = true)
    @Mapping(target = "reviewId", ignore = true)
    @Mapping(target = "shopId", ignore = true)
    @Mapping(target = "userId", ignore = true)
    @Mapping(target = "createTime", ignore = true)
    ReviewReply toReviewReply(ReviewReplyDTO dto);

    @Mapping(source = "id", target = "reviewId")
    @Mapping(source = "isAnonymous", target = "anonymous")
    @Mapping(target = "userNickname", ignore = true)
    @Mapping(target = "userAvatar", ignore = true)
    @Mapping(target = "reply", ignore = true)
    @Mapping(target = "reviewItems", ignore = true)
    ReviewVO toReviewVO(Review review);

    @Mapping(target = "productName", ignore = true)
    @Mapping(target = "imageUrls", ignore = true)
    ReviewItemVO toReviewItemVO(ReviewItem item);

    ReviewReplyVO toReviewReplyVO(ReviewReply reply);
}
